{extend name="base" /}
{block name="content"}
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}"><i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>系统</span>
            <span class="icon-angle-right"></span>
            <span>会员管理</span>
            <span class="icon-angle-right"></span>
            <span>会员列表</span>
            <a class="u-flush"><i class="icon-repeat"></i></a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">
            <table class="m-table">
                <tr>
                    <th>
                        <div class="m-options cf">
                             <div class="m-opts fl"><a href="{:url('add')}" class="u-btn"><i class="icon-plus"></i>录入会员</a></div>
                            <div class="m-search fr">
                                <form action="" class="layui-form">
                                    <div class="lay-select">
                                        <select name="role_id">
                                            <option value="0">请选择会员角色</option>
                                            {foreach name="roles" item="role"}
                                            <option value="{$role.id}"{if condition="input('get.role_id') eq $role['id']"} selected{/if}>{$role.name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <label for="keywords">姓名</label>
                                    <input type="text" name="username" id="username" class="u-ipt u-ipt-def" placeholder="请输入会员姓名" value="{$username}" />
                                    <label for="keywords">手机号</label>
                                    <input type="text" name="mobile" id="mobile" class="u-ipt u-ipt-def" placeholder="请输入会员手机号" value="{$mobile}" />

                                    <input type="submit" class="u-btn u-search" value="查看" />
                                </form>
                            </div>
                        </div>
                    </th>
                </tr>
            </table>
            <form class="layui-form">
                <table class="m-table mt-10">
                    <tbody class="datas">
                        <tr>
                            <th width="5%">ID</th>
                            <th width="8%">姓名</th>
                            <th width="8%">手机号</th>
                            <th width="8%">昵称</th>
                            <th width="6%">会员等级</th>
                            <th width="6%">剩余积分</th>
                            <th width="8%">会员生日</th>
                            <th width="5%">是否绑定</th>
                            <th width="8%">录入时间</th>
                            <th width="18%">操作</th>
                        </tr>
                        {foreach name="data" item="v"}
                        <tr>
                            <td>{$v.id}</td>
                            <td>{$v.username}</td>
                            <td>{$v.mobile}</td>
                            <td>{$v.nickname}</td>
                            <td>{$v.role_name}</td>
                            <td>{$v.points}</td>
                            <td>{$v.birthday}</td>
                            <td>
                                {if $v.is_binding}
                                    已绑定
                                {else}
                                    未绑定
                                {/if}
                            </td>
                            <td>{$v.create_time}</td>
                            <td class="m-opt">
                                <button type="button" data-id="{$v.id}"	class="layui-btn layui-btn-xs add">添加</button>
                                <button type="button" data-id="{$v.id}" class="layui-btn layui-btn-xs layui-btn-danger deduction">扣除</button>
                                <a href="/manage/members/points_log?id={$v.id}" class="layui-btn layui-btn-xs layui-btn-normal">积分明细</a>
                                <a href="/manage/members/exchange_log?id={$v.id}" class="layui-btn layui-btn-xs layui-btn-normal">兑换记录</a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </form>
            {include file="public:page" /}
        </div>
    </div>
</div>
{/block}

{block name="extrajs"}
{include file="laypage" /}
<script>
    $(function(){
        //添加
        $(".add").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm('确定执行此操作吗?', {icon: 3, title:'提示'}, function(index){
                layer.prompt({
                    formType: 0,
                    value: '',
                    title: '请输入要添加的积分',
                }, function(value, index, elem){
                    if (!value){
                        dialog.error("请输入要添加的积分");
                        return false;
                    }
                    $.post("/manage/members/add_and_deduction_points",{
                        id : id,
                        type : 0,
                        points : value,
                    },function (res) {
                        if (!res.status){
                            dialog.success(res.message,function(){
                                layer.close(index);
                                window.location.reload();
                            })
                        }else{
                            dialog.error(res.message,function(){
                                layer.close(index);
                                window.location.reload();
                            })
                        }
                    });
                });
                layer.close(index);
            });
        })
        //扣除
        $(".deduction").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm('确定执行此操作吗?', {icon: 3, title:'提示'}, function(index){
                layer.prompt({
                    formType: 0,
                    value: '',
                    title: '请输入要扣除的积分',
                }, function(value, index, elem){
                    if (!value){
                        dialog.error("请输入要扣除的积分");
                        return false;
                    }
                    $.post("/manage/members/add_and_deduction_points",{
                        id : id,
                        type : 1,
                        points : value,
                    },function (res) {
                        if (!res.status){
                            dialog.success(res.message,function(){
                                layer.close(index);
                                window.location.reload();
                            })
                        }else{
                            dialog.error(res.message,function(){
                                layer.close(index);
                                window.location.reload();
                            })
                        }
                    });
                });
                layer.close(index);
            });
        })
    })
</script>
{/block}